//
//  Array+.swift
//  BearCalendar
//
//  Created by liyb on 2024/10/27.
//

import Foundation

public extension Array where Element == String {
    
    /// 取前几个小于maxLength的元素
    /// - Parameters:
    ///   - count: 前几个
    ///   - maxLength: 字符串长度，默认为 0，0 为不处理
    /// - Returns: 结果
    func prefix(count: Int, maxLength: Int = 0) -> [String] {
        if self.count < count, let first = first {
            return [first]
        }
        let result = filter { $0.count <= maxLength }
        return result.isEmpty ? [NSLocalizedString("BearCalendar.Tag.Empty", bundle: moduleBundle, comment: "无")] : Array(result.prefix(count))
    }
}
